package gold.digger;

import gold.utils.InputUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC861 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int matrixScore(int[][] grid) {
            int m = grid.length, n = grid[0].length, res = m * (int) (Math.pow(2, n - 1));
            for (int i = 1; i < n; i++) {
                int zeroCount = 0, oneCount = 0;
                for (int j = 0; j < m; j++) {
                    boolean curIsOne = grid[j][i] == grid[j][0];
                    if (curIsOne) oneCount++;
                    else zeroCount++;
                }

                res += Math.max(zeroCount, oneCount) * (int) (Math.pow(2, n - 1 - i));
            }

            return res;
        }
    }

    public void run() {
        Solution solution = new Solution();
        int[][] arr = InputUtil.toDoubleIntegerArray("[[0,0,1,1],[1,0,1,0],[1,1,0,0]]");
        System.out.println(solution.matrixScore(arr));
    }

    public static void main(String[] args) throws Exception {
        LC861 an = new LC861();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
